<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav main-header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            设备任务单列表
        </div>
    </header>
    <script id="chkBillTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setTask('{{= it[index].taskId }}','{{= it[index].taskCode }}','{{= it[index].chkCode }}','{{= it[index].chkName }}','{{= it[index].equipmentno }}','{{= it[index].equipmentname }}','{{= it[index].actualBeginDate }}','{{= it[index].taskResult }}');">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-inner ">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title aui-font-size-14">
                            任务编码：{{= it[index].taskCode }}
                        </div>
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        设备模板编码：{{= it[index].chkCode }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        设备模板名称：{{= it[index].chkName }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        设备编码：{{= it[index].equipmentno }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        设备名称：{{= it[index].equipmentname }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        审核时间：{{= it[index].reviewDate }}
                    </div>
                </div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-bar aui-bar-nav sub-header"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;padding-bottom: 50px;">
        <div class="white_background">

            <ul class="aui-list aui-form-list">

                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="font-size: 14px;">设备编码</div>
                        <input type="text" class="aui-input" placeholder="请 扫描/输入 设备编码"
                            style="width: 80%;font-size: 14px;" id="equipCode">
                        <i class="aui-input-addon aui-iconfont aui-icon-scan " style="font-size: 1.6rem"
                            onclick="toScanner();"></i>
                    </div>
                </li>

                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width:150px;font-size: 14px;">审核日期</div>
                        <div class="aui-list-item-input" onclick="timePicker();">
                            <input type="text" placeholder="选择审核日期" style="padding-left: 20px;font-size: 14px;"
                                class="aui-input" id="reviewDate">
                        </div>
                    </div>
                </li>

            </ul>
            <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
        </div>

        <ul class="aui-list aui-media-list" id="taskList">

        </ul>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var boxnum = "";
    var code = "";
    apiready = function () {
        var query = api.pageParam.query;
        code = query.code
        if (code != undefined && code != null && code != "") {
            if (code == '0') {
                document.getElementById("title").innerHTML = "设备保养";
            } else if (code == '1') {
                document.getElementById("title").innerHTML = "设备点检";
            }
        }
    };

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#reviewDate").val(date);
                doSearch();
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150,//扫描窗口的上边距
            width: 250,//扫描窗口的宽
            height: 250,//扫描窗口的高
            useColor: false,//是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF',//渐变起始颜色
            endColor: '#7F08C8FF',//渐变结束颜色
            animTime: 2200,//扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            var SMequipCode = ret;
            var text = document.getElementById("equipCode");
            text.value = SMequipCode;
            doSearch()
        });

    }
    //查询
    function doSearch() {

        var reviewDate = $("#reviewDate").val();
        var equipCode = $("#equipCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/geChkTaskEquip";
        var data = {
            values: {
                un: un,
                reviewDate: reviewDate,
                equipCode: equipCode,
                code: code + ''
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    var evaluation = doT.template($api.dom('#chkBillTemp').innerHTML);
                    $api.dom('#taskList').innerHTML = evaluation(list);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setTask(taskId, taskCode, chkCode, chkName, equipmentno, equipmentname, actualBeginDate, taskResult) {
        console.log(taskId, taskCode)
        var name = 'searchEquipTask-AC'
        api.openWin({
            name: 'uemChkTask-searchEquipTask-AC',
            url: 'uemChkTask-searchEquipTask-AC.html',
            pageParam: {
                url: 'searchEquipTask-AC.html',
                name: name,
                taskId: taskId,
                taskCode: taskCode,
                equipCode: equipmentno,
                equipName: equipmentname,
                actualBeginDate: actualBeginDate,
                taskResult: taskResult,
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>